package com.haoshuang.zhouzhoubang.ui.page.message.child.error

import com.haoshuang.zhouzhoubang.model.api.ApiRepo
import com.haoshuang.zhouzhoubang.model.bean.CallBean
import com.haoshuang.zhouzhoubang.model.bean.ErrorMessageBean
import com.mufeng.libs.base.BaseViewModel
import com.mufeng.libs.net.ResponseBean
import com.mufeng.libs.net.netRequest
import com.mufeng.libs.state.StateData
import com.mufeng.libs.state.StatefulMutableLiveData

class ErrorMessageViewModel : BaseViewModel() {

    /**
     * 师傅同意处罚
     */
    val masterAgreePunishmentData = StatefulMutableLiveData<ResponseBean<Any>>()
    fun masterAgreePunishment(id: String) = netRequest {
        start { masterAgreePunishmentData.value = StateData.Loading }
        request { ApiRepo.masterAgreePunishment(id) }
        success { masterAgreePunishmentData.value = StateData.Success(it) }
        error { code, msg ->
            masterAgreePunishmentData.value = StateData.Error(code, msg)
        }
    }
    /**
     * 师傅同意处罚 订单投诉
     */
    val masterAgreeComplaintData = StatefulMutableLiveData<ResponseBean<Any>>()
    fun masterAgreeComplaint(id: String) = netRequest {
        start { masterAgreeComplaintData.value = StateData.Loading }
        request { ApiRepo.masterAgreeComplaint(id) }
        success { masterAgreeComplaintData.value = StateData.Success(it) }
        error { code, msg ->
            masterAgreeComplaintData.value = StateData.Error(code, msg)
        }
    }

    /**
     * 设置消息已读
     */
    val masterSetMessageReadData = StatefulMutableLiveData<ResponseBean<Any>>()
    fun masterSetMessageRead(id: Int?, type: Int) = netRequest {
        start { masterSetMessageReadData.value = StateData.Loading }
        request { ApiRepo.masterSetMessageRead(id, type)  }
        success { masterSetMessageReadData.value = StateData.Success(it) }
        error { code, msg ->
            masterSetMessageReadData.value = StateData.Error(code, msg)
        }
    }

    /**
     * 获取异常消息
     */
    val getMasterOrderFeedbackMsgData = StatefulMutableLiveData<ResponseBean<MutableList<ErrorMessageBean>>>()
    fun getMasterOrderFeedbackMsg(p: Int, is_deal: Int) = netRequest {
        start { getMasterOrderFeedbackMsgData.value = StateData.Loading }
        request { ApiRepo.getMasterOrderFeedbackMsg(p, is_deal)  }
        success { getMasterOrderFeedbackMsgData.value = StateData.Success(it) }
        error { code, msg ->
            getMasterOrderFeedbackMsgData.value = StateData.Error(code, msg)
        }
    }

    /**
     * 删除订单消息
     */
    val delApplyReworkMsgData = StatefulMutableLiveData<ResponseBean<Any>>()
    fun delApplyReworkMsg(id: Int?) = netRequest {
        start { delApplyReworkMsgData.value = StateData.Loading }
        request { ApiRepo.delApplyReworkMsg(id)  }
        success { delApplyReworkMsgData.value = StateData.Success(it) }
        error { code, msg ->
            delApplyReworkMsgData.value = StateData.Error(code, msg)
        }
    }
}